package 一维数组.习题;

import java.util.Arrays;
//奇数位于偶数之前
public class text_3 {
    public static void main(String[] args) {
        int[] array={1,2,3,4,5};
        int[] array1 = fun1(array);
        System.out.println(Arrays.toString(array1));
    }
    public static int[] fun1(int[] array){
        int index = 0;
        int[] array1 = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            if(array[i]%2!=0) {
                array1[index] = array[i];
                index++;
            }
        }
        for (int i = 0; i < array.length; i++) {
            if(array[i]%2==0){
                array1[index] = array[i];
                index++;
            }
        }
        return array1;
    }
}
